

<template>
  <div>
    <el-button class="butB_Sel" @click="printBtn()">打印1</el-button>
    <el-button class="butB_Sel" @click="printBtn2()">打印2</el-button>
    <div class="app-container" id="printcons">
      <div
        class=""
        style="margin: auto; padding: 0px 20px;  width: 950px; font-size: 14px"
      >
        <!-- <div> -->

        <table
          border="0"
          width="100%"
          align="center"
          cellspacing="0"
          cellpadding="0"
        >
          <thead>
            <tr class="title" style="line-height: 60px;">
              <td  colspan="6" style="font-size: 26px;padding-top:50px;padding-bottom:20px;text-align: center;">临时医嘱单</td>
            </tr>
            <tr class="table_t" >
              <td style="padding-bottom:20px">病区:{{ tabeldata.room }}</td>
              <td style="padding-bottom:20px">床号:{{ tabeldata.name }}</td>
              <td style="padding-bottom:20px">姓名:{{ tabeldata.member.name }}</td>
              <td style="padding-bottom:20px">
                性别:{{
                  tabeldata.member.gender == 1
                    ? "男"
                    : tabeldata.member.gender == 2
                    ? "女"
                    : "未知"
                }}
              </td>
              <td style="padding-bottom:20px">年龄:{{ tabeldata.member.age }}岁</td>
              <td style="padding-bottom:20px">住院号:{{ tabeldata.ipt_no }}</td>
            </tr>
            <tr  style="text-align: center;">
              <td colspan="2"  style="border:1px solid black;border-right:0">医嘱时间</td>
              <!-- <td rowspan='2' style="width:50px;height:40px">执行标志</td> -->
              <td rowspan="2" style="border:1px solid black;border-right:0">临时医嘱</td>
              <td rowspan="2"  style="border:1px solid black;border-right:0">医师签名</td>

              <td rowspan="2" style="border:1px solid black;border-right:0">执行时间</td>

              <td rowspan="2"  style="border:1px solid black">执行者签名</td>
            </tr>
            <tr  style="text-align: center;" >
              <td  style="border:1px solid black;border-top:0;border-right:0">日期</td>
              <td  style="border:1px solid black;border-top:0;border-right:0">时间</td>
            </tr>
          </thead>
          <tbody>
            <tr
              v-for="(item, index) in drug2"
              :key="index"
               style="text-align: center;"
            >
              <td style="border:1px solid black;padding:10px 0;width: 200px;">{{ item.start_time.split(" ")[0] }}</td>
              <td style="border:1px solid black;width: 100px;">{{ item.start_time.split(" ")[1] }}</td>

              <td style="border:1px solid black;">
                {{ item.business_name }}

              </td>
              <td style="border:1px solid black;width: 100px;">{{ item.advice_doctor_name }}</td>
              <td style="border:1px solid black;width: 200px;">{{ item.execution_time }}</td>
              <td style="border:1px solid black;width: 100px;">{{ item.execution_user_name }}</td>
            </tr>
          </tbody>
                <tfoot  class="footer"   style="line-height:30px;width:100%;">
<!--                  <tr>-->
<!--                    <td colspan="20" style="width:100%;text-align:center;border:1px solid black;border-top:0px">大写合计:&nbsp;{{tabeldata.dx_cost}}&nbsp;&nbsp;小写合计:&nbsp;{{tabeldata.cost}}</td>-->
<!--                  </tr>-->
              <tr v-if="showTFoot">

                                 <td colspan="20" style="display:flex;" >当前是第<font tdata="PageNO" format="0" >##</font>页</span>/共<font tdata="PageCount" format="0" >##</font></span>页</td>

              </tr>
              <tr v-else style="line-height:60px">

                                 <td colspan="1"  style="display:flex;padding-bottom:20px;border:0" >&nbsp;</td>
               </tr>
            </tfoot>
        </table>
        <!-- </div>
        <p>第{{ it + 1 }}页 /共 {{ drug2.length }} 页 审核医生：</p> -->
      </div>
    </div>
  </div>
</template>
<script>
import { getdictIndex } from "@/api/register";
export default {
  props: ["yizhudata", "type"],
  data() {
    return {
      tabeldata: {
        name: "",
        room: "",
      },
      showTFoot: true,
      sourcelist: [],
      arrdata: [],
      dayin: false,
      drug2: [],
    };
  },

  mounted() {
    this.yizhudata = JSON.parse(this.$route.query.yizhudata);

    this.tabeldata = this.yizhudata.info;
    console.log(this.yizhudata);
    this.tabeldata.room_nameA = this.tabeldata.room_name.split("/");
    this.tabeldata.room = this.tabeldata.room_nameA[1];
    this.tabeldata.name = this.tabeldata.room_nameA[3];
    this.tabeldata2 = this.yizhudata.advice;

    this.arrdata = this.tabeldata2;

    this.drug2 = this.arrdata;

    console.log("tabeldata2", this.tabeldata2);
    console.log("dirg", this.drug2);
    //  this.tianjiaids();
  },
  // watch: {
  //   yizhudata(n) {
  //     console.log(n);
  //     this.drug2 = [];
  //     this.tabeldata2 = [];
  //     this.tabeldata = n.info;
  //     this.tabeldata.room_nameA = this.tabeldata.room_name.split("/");
  //     this.tabeldata.room = this.tabeldata.room_nameA[1];
  //     this.tabeldata.name = this.tabeldata.room_nameA[3];
  //     this.tabeldata2 = n.advice;
  //     this.arrdata = this.tabeldata2;
  //     for (let i = 0; i < this.tabeldata2.length; i++) {
  //       if (this.tabeldata2[i].advice_type == 2) {
  //         this.tabeldata2[i].id2 = "";
  //         var arr = {
  //           advice_doctor: "",
  //           advice_doctor_name: "··",
  //           business_name: this.tabeldata2[i].show_usage,
  //           end_time: "··",
  //           start_time: "··",
  //           advice_type: "0",
  //           is_group: this.tabeldata2[i].is_group,
  //           stop_doctor_name: "··",
  //           stop_nurse_name: "··",
  //           specification: "··",
  //           usage: "··",
  //           used_frqu: {
  //             name: "",
  //           },
  //         };
  //         this.arrdata.splice(i + 1, 0, arr);
  //       }
  //     }
  //     this.tabeldata2 = this.arrdata;
  //     if (this.tabeldata2.length > 42) {
  //       var arr = this.tabeldata2;
  //       for (let i = 0; i < Math.ceil(arr.length / 42); i++) {
  //        this.drug2.push(arr.slice(i*42, 42*(i+1)));
  //       }
  //       console.log(this.drug2);
  //     } else {
  //       this.drug2.push(this.tabeldata2);
  //     }
  //     var aty = this.drug2[this.drug2.length - 1];
  //     var num = 42 - parseInt(aty.length);

  //     if (num < 42) {
  //       for (let i = 0; i < num; i++) {
  //         this.drug2[this.drug2.length - 1].push({
  //           advice_doctor: "",
  //           advice_doctor_name: "",
  //           business_name: "",
  //           end_time: " ",
  //           start_time: " ",
  //           is_group: 0,
  //           stop_doctor_name: "",
  //           stop_nurse_name: "",
  //           specification: "",
  //           advice_type: "0",
  //           show_usage: "",
  //           used_frqu: {
  //             name: "",
  //           },
  //         });
  //       }
  //     }
  //     this.tianjiaids();
  //   },
  // },
  methods: {
    tianjiaids() {
      for (let j = 0; j < this.tableData1.length; j++) {
        if (
          this.tableData1[j].is_group != null &&
          this.tableData1[j].is_group != 0
        ) {
          var arr = [];
          for (let i = 0; i < this.tableData1.length; i++) {
            if (this.tableData1[i].is_group == this.tableData1[j].is_group) {
              arr.push(i);
            }
          }
          console.log(arr);
          for (let i = 0; i < arr.length; i++) {
            if (i == 0) {
              this.tableData1[arr[i]].id2 = "1";
            } else if (i == arr.length - 1) {
              this.tableData1[arr[arr.length - 1]].id2 = "1";
            } else {
              this.tableData1[arr[i]].id2 = "1";
            }
          }
        }
      }
    },
    getindex() {
      getdictIndex({ group_id: "40" }).then((res) => {
        let data = res.data;
        data.forEach((item, key) => {
          if (item.id == 40) {
            this.sourcelist = item.items;
          }
        });
      });
    },
    getpint() {
      this["_API"].getPrintReport({ id: this.id }).then((res) => {
        if (res.code == 200) {
          this.tabeldata = res.data;
          this.tabeldata.source = this.mapxing(this.tabeldata.source);
        }
      });
    },

    mapxing(num) {
      var art = "";
      this.sourcelist.map(function (value, i, array) {
        if (value.id == num) {
          art = value.name;
        }
      });
      console.log(art);
      return art;
    },
    printBtn(e) {
      this.dayin = true;
      this.showTFoot = false;
      setTimeout(() => {
        this.dayinfun();
      }, 200);
    },
    printBtn2(e) {
      this.CreateOneFormPage();
    },
    CreateOneFormPage() {
      this.LODOP = getLodop();
      this.LODOP.ADD_PRINT_TABLE(
        0,
        0,
        "100%",
        "100%",
        document.getElementById("printcons").innerHTML
      );
      this.LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT", "Auto-Width");
      this.LODOP.SET_PRINT_STYLEA(0, "LinkedItem", -1);
      this.LODOP.PREVIEW();
    },
    dayinfun() {
      this.remove_ie_header_and_footer();
      let subOutputRankPrint = document.getElementById("printcons");
      console.log(subOutputRankPrint.innerHTML);
      let newContent = subOutputRankPrint.innerHTML;
      let oldContent = document.body.innerHTML;
      document.body.innerHTML = newContent;
      window.print();
      window.open("", "_self").close(), this.$emit("reload");
      document.body.innerHTML = oldContent;
      return false;
    },
    //去掉页眉和页脚
    remove_ie_header_and_footer() {
      var hkey_path;
      hkey_path =
        "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
      try {
        var RegWsh = new ActiveXObject("WScript.Shell");
        RegWsh.RegWrite(hkey_path + "header", "");
        RegWsh.RegWrite(hkey_path + "footer", "");
      } catch (e) {}
    },
  },
};
</script>
<style media="print">
@page {
  size: auto; /* auto is the initial value */
  margin: 0mm; /* this affects the margin in the printer settings */
}
@media print {
}
body {
  -webkit-print-color-adjust: exact;
}
#printcons >>> td {
  width: 150px;
  height: 40px !important;

  /* border: 0.5px solid #000000; */
  padding: 0rem;
  margin: 0rem;
  text-align: center;
}
</style>
<style lang='scss' scoped>
#printcons >>> tr {

  margin: 0rem;
}
#printcons >>> td {

  /* border: 0.5px solid #000000; */
  padding: 0rem;
  margin: 0rem;
  text-align: center;
  font-size:12px;

}

.app-container {
  .title {
    text-align: center;
    td {
      font-size: 26px;

    }
  }
}
</style>
